var gridList
    , moduleId = RequestURLParam.getParam("moduleId");
$(document).ready(function () {
    gridList = new dataGrid("gridList");
    gridList.load({"deleteFlag": 2, 'moduleId': moduleId});
});

/*
* 刷新
* */
function reload_data() {
    $("#workFlowCode").val("");
    gridList.reload({"deleteFlag": 2, 'moduleId': moduleId, 'wfName': ''});
}

//查询
function search_query() {
    var key = $('#workFlowCode').val(),
        param = {'deleteFlag': 2, 'moduleId': moduleId, 'wfName': key};
    gridList.reload(param);
    $("#workFlowCode").val("");
}

function formatOper(e) {
    var e = e || window
        , row = e.record
        ,
        btn = "<a class='layui-btn layui-btn-xs' hideFocus='' href='javascript:void(0)' onClick='recover(\"" + row.wfId + "\",\"" + row.wfName + "\")'><i class='layui-icon'>&#xe9aa;</i>恢复</a>" +
            "<a class='layui-btn layui-btn-danger layui-btn-xs' hideFocus='' href='javascript:void(0)' onClick='deleteData(\"" + row.wfId + "\",\"" + row.wfName + "\")'><i class='layui-icon'>&#xe640;</i>删除</a>";
    return btn;
}

//恢复
function recover(fid, wfName) {
    layer.confirm('确定要恢复' + wfName + '么？', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        ActHttpRequest('/wf/workflow/update', {"wfId": fid, 'deleteFlag': 1}, function (data) {
            if (data.OK === "OK") {
                layer.msg('操作成功', {icon: 1, time: 2000, shade: 0.3});
                reload_data();
            } else {
                layer.msg(data.message, {icon: 2, time: 2000, shade: 0.3});
            }
        }, null, null, null, '加载中。。。', false);
    });
}

/*
* @author: wj
* @description: 删除流程
* @date: 2019/3/7 17:01
* @param
* @return
*/
function deleteData(fid, wfName) {
    console.log(fid)
    var param = {
        'wfId': fid
    };
    layer.confirm('确定要删除' + wfName + '么?删除不可恢复', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        $.ajax({
            type: 'DELETE'
            , url: '/wf/workflow/remove'
            , data: param
            , dataType: 'json'
            , success: function () {
                layer.msg('操作成功', {icon: 1, time: 1000, shade: 0.3});
                reload_data();
            }
            , error: function () {
                layer.msg('操作失败！', {
                    icon: 2,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                })
            }
        });
    });
}


//批量回收
function batchRecycle() {
    var dataStr = gridList.getCheckData();
    var data = JSON.parse(dataStr);

    if (data == null || data.length == 0) {
        layer.msg('请选择要恢复的模块！', {
            icon: 0,
            time: 1000, //1秒关闭（如果不配置，默认是3秒）
            shade: 0.3
        });
        return;
    }

    var ids = [];
    $.each(data, function (index, temp) {
        ids.push(temp.wfId);
    });
    layer.confirm('确定要恢复选中的模块么？', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        var param = {
            'wfId': ids.join()
        };
        console.log(ids)
        ActHttpRequest('/wf/workflow/batchsRecoverWfWorkflow', param, function (data) {
            if (data.OK === "OK") {
                layer.msg('操作成功', {icon: 1, time: 1000, shade: 0.3});
                reload_data();
            } else {
                layer.msg(data.message, {icon: 2, time: 2000, shade: 0.3});
            }
        }, null, null, null, '加载中。。。', false);

    });
}


